package utils

import (
	"io"
	"log"
	"os"
	"server/config"
)

var (
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
	Request *log.Logger
)

func init() {
	errFile, err := OpenFile(config.LogStoreDir + "errors.log")
	info, err := OpenFile(config.LogStoreDir + "info.log")
	warning, err := OpenFile(config.LogStoreDir + "warning.log")
	request, err := OpenFile(config.LogStoreDir + "req.log")
	if err != nil {
		log.Fatalln("打开日志文件失败：", err)
	}
	iw := io.MultiWriter(os.Stdout, info)
	log.SetOutput(iw)
	Info = log.New(iw, "Info:", log.Ldate|log.Ltime|log.Lshortfile)

	ww := io.MultiWriter(os.Stdout, warning)
	log.SetOutput(ww)
	Warning = log.New(ww, "Warning:", log.Ldate|log.Ltime|log.Lshortfile)

	ew := io.MultiWriter(os.Stderr, errFile)
	log.SetOutput(ew)
	Error = log.New(ew, "Error:", log.Ldate|log.Ltime|log.Lshortfile)

	Request = log.New(io.MultiWriter(os.Stderr, request), "Request:", log.Ldate|log.Ltime|log.Lshortfile)
}
